package com.demo.datastructure.reorder.shellSort;

import com.demo.datastructure.reorder.Example;

/**
 * @author ljr
 * @version 1.0
 * @description: 希尔排序
 * @date 2021/9/17 21:19
 */
public class MyShellSort6 implements Example {

    @Override
    public void sort(Comparable[] a) {
        int n = a.length;
        int h = 1;
        while(h < n/3) h = h*3+1;
        while(h > 0){
            for(int i = h; i < n; i++){
                for(int l = i; l >= h && less(a[l],a[l-h]); l -= h){
                    exch(a,l, l-h);
                }
            }
            h /= 3;
        }
    }

}
